package com.jn.exam.webSocket.component;

import com.alibaba.fastjson.JSONObject;
import com.jn.exam.webSocket.entity.MessageResult;
import com.jn.exam.webSocket.utils.Constants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * 发布消息
 *
 * @author 江南大学1033190417
 * @date 2022/3/4 20:31
 */
@Component
public class FanoutSender {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    public void sendMessage(Map<String, MessageResult> rabbitMessageList){
        System.out.println("发送消息"+rabbitMessageList);
        rabbitTemplate.convertAndSend(Constants.FANOUT_EXCHANGE_NAME,"", JSONObject.toJSONString(rabbitMessageList));
    }
}
